<?php
// 弃用，弃用，弃用，因为大众快三，大众时时彩，大众十一选五的期号规则都是一样的。期号脚本转到createdflott.inc.php里面
defined('IN_YuLin') || exit('NO PERMIT!');
echo '<pre>';
// 获取各类时时彩的的后台设置信息
$lottCateTab  = Table('lottery_category');
$lottTab      = Table('lottery');
$field        = 'cate.name as cate_name, cate.tags as cate_tags, lott.sname as lott_sname, lott.title as lott_name, lott.id as lott_id';
// 这里查询语句不再针对时时彩， 而是所有大众彩
$sql          = 'SELECT ' . $field . ' FROM ' . $lottCateTab . ' AS cate
                LEFT JOIN ' . $lottTab . ' AS lott
                ON cate.`id` = lott.`cate_id`
                WHERE 1';

$sscList = $db->getall($sql);
if (!$sscList) {
    echo '彩种信息获取失败！';
    return;
}
// 设置彩种补全信息
foreach ($sscList as $key => $value){
    switch ($value['lott_sname']){
        case 'dfssc':
        case 'f1k3':
        case 'df11x5':
            $sscList[$key]['total_by_day'] = '1440';
            $sscList[$key]['begin_index']  = '1';
            $sscList[$key]['time_slot']    = array(
                '0' => array('slot'   => 'all', 'secont' => 1 * 60, 's_total' => 1440),
            );
            break;
        default:
            break;
    }
}
$preTab      = Table('lottery_k3');
// 准备进行当天期号生成
$baseDayTime   = strtotime(date('Y-m-d', strtotime('+1 day')));
$baseDayTime   = strtotime(date('Y-m-d'));
$dayInfo       = date('Ymd', $baseDayTime);
foreach ($sscList as $k => $v){
    if (!$v['time_slot']) continue;
    $checkCountSql  = 'SELECT COUNT(id) as cnt FROM ' . $preTab . ' WHERE tid = ' . $v['lott_id'] . ' AND `day` = "' . $baseDayTime . '"';
    $checkCountInfo = $db->getrow($checkCountSql);
    if ($checkCountInfo['cnt'] == $v['total_by_day']) continue;
    $index          = 0;
    $begin_index    = $v['begin_index'];
    $btime          = $baseDayTime;
    foreach ($v['time_slot'] as $tk => $tv){
        if ($tv['slot'] == 'all'){
            // 全天类型
            for($i = 0; $i < $tv['s_total']; $i++){
                $qihao  = $dayInfo . str_pad( ($begin_index),4,0,STR_PAD_LEFT);
                $btime += $tv['secont'];
                // 基础期号累加
                $begin_index++;
                $ins = [];
                $ins['tid']		   = $v['lott_id'];
                $ins['period']	   = $qihao;
                $ins['starttime']  = $btime - $tv['secont'];
                $ins['stoptime']   = $btime;
                $ins['createtime'] = time();
                $ins['day']		   = $dayInfo;
                $db->add('lottery_k3',$ins);
                print_r($ins);
            }
        }
    }
    
}

exit('success');


